package com.wt.admin.service.image.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wt.admin.code.image.ImageClassification3100;
import com.wt.admin.domain.dto.image.ImageClassificationDTO;
import com.wt.admin.domain.entity.image.ImageClassificationEntity;
import com.wt.admin.domain.vo.image.ImageClassificationVO;
import com.wt.admin.domain.vo.image.ImageFeaturesListVO;
import com.wt.admin.mapper.image.ImageClassificationMapper;
import com.wt.admin.service.image.ImageClassificationService;
import com.wt.admin.util.AssertUtil;
import com.wt.admin.util.PageUtil;
import org.dromara.easyai.yolo.YoloConfig;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

@Service
public class ImageClassificationServiceImpl extends ServiceImpl<ImageClassificationMapper, ImageClassificationEntity> implements ImageClassificationService {

    @Resource
    private ImageClassificationMapper imageClassificationMapper;

    @Override
    public ImageClassificationVO add(ImageClassificationDTO data) {
        AssertUtil.Str.isEmpty(data.getTitle(), ImageClassification3100.CODE_3100);
        AssertUtil.objIsNull(data.getImageWidth(), ImageClassification3100.CODE_3101);
        AssertUtil.objIsNull(data.getImageWidth(), ImageClassification3100.CODE_3102);
        if(ObjectUtil.isEmpty(data.getYoloConfig())){
            data.setYoloConfig(new YoloConfig());
        }
        save(data);
        return null;
    }

    @Override
    public ImageClassificationVO edit(ImageClassificationDTO data) {
        AssertUtil.objIsNull(data.getId(), ImageClassification3100.CODE_3103);
        AssertUtil.Str.isEmpty(data.getTitle(), ImageClassification3100.CODE_3100);
        if(ObjectUtil.isEmpty(data.getYoloConfig())){
            data.setYoloConfig(new YoloConfig());
        }
        updateById(data);
        return null;
    }

    @Override
    public List<ImageClassificationVO> list(ImageClassificationDTO data) {
        return imageClassificationMapper.list(data);
    }

    @Override
    public ImageClassificationVO del(ImageClassificationDTO data) {
        AssertUtil.objIsNull(data.getId(), ImageClassification3100.CODE_3103);
        removeById(data);
        return null;
    }

    @Override
    public ImageClassificationEntity byId(Integer id) {
        return imageClassificationMapper.selectById(id);
    }
}
